//
//  KRTreatmentVC.m
//  QuickCare
//
//  Created by 张凯锐 on 16/7/12.
//  Copyright © 2016年 lidabiao. All rights reserved.
//

#import "KRTreatmentVC.h"

@interface KRTreatmentVC ()<UITableViewDelegate,UITableViewDataSource>
//治疗方式
@property (nonatomic,strong) NSArray *mode;
//模型cell
@property (nonatomic,strong) UITableViewCell *cell;
@end

@implementation KRTreatmentVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.tableView.showsHorizontalScrollIndicator = NO;
    self.tableView.showsVerticalScrollIndicator = NO;
    self.mode = @[@"手术治疗",@"保守治疗",@"药物治疗"];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"确定" style:UIBarButtonItemStylePlain target:self action:@selector(clickDetermine)];
}

//点击确定的方法
- (void)clickDetermine {
    //代理传值
    if ([self.delegate respondsToSelector:@selector(treatmentVCDelegate:treatmentName:)]) {
        [self.delegate treatmentVCDelegate:self treatmentName:self.cell.textLabel.text];
    }
    
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark - UITableViewDataSource数据源
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.mode.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
    }
    //给cell赋值
    cell.textLabel.text = self.mode[indexPath.row];
    return cell;
}

#pragma mark - UITableViewDelegate代理
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    //将上一个cell的accessoryType设置为None类型
    self.cell.accessoryType = UITableViewCellAccessoryNone;
    //将选中的cell的accessoryType设置为Checkmark类型
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    cell.accessoryType = UITableViewCellAccessoryCheckmark;
    //赋值给模型cell
    self.cell = cell;
}



@end
